﻿using System;
using System.Collections.Generic;
using System.Text;
//
using PerceptiveMCAPI;
using PerceptiveMCAPI.Types;
//
namespace PerceptiveMCAPI_Test
{

   public class apiXmlRpcRequestDisplayFormat
   {
      #region ------------------------------------------------------------------- security
      public static string FormatParms( apikeysParms p )
      {
         return string.Format( "username: [{0}], password: [{1}], apikey: [{2}], expired: [{3}]",
            p.username, p.password, p.apikey, p.expired );
      }
      public static string FormatParms( apikeyAddParms p )
      {
         return string.Format( "username: [{0}], password: [{1}], apikey: [{2}]",
            p.username, p.password, p.apikey );
      }
      public static string FormatParms( apikeyExpireParms p )
      {
         return string.Format( "username: [{0}], password: [{1}], apikey: [{2}], apikeyToExpire: [{3}]",
              p.username, p.password, p.apikey, p.apikeyToExpire );
      }
      #endregion

      #region ------------------------------------------------------------------- helper

      public static string FormatParms( chimpChatterParms p )
      {
         return string.Format( "apikey: [{0}]", p.apikey );
      }
      public static string FormatParms( createFolderParms p )
      {
         return string.Format( "apikey: [{0}], name: [{1}]", p.apikey, p.name );
      }
      public static string FormatParms( ecommAddOrderParms p )
      {
         StringBuilder sb = new StringBuilder(); string items = "";
         if ( p.order.items.Count > 0 )
         {
            foreach ( var item in p.order.items )
            {
               sb.AppendFormat( "#{0}: ProdId=>{1}, ProdName=>{2}, CatId=>{3}, CatName=>{4}, Qty=>{5}, Cost=>{6:N2} | ",
                  item.line_num, item.product_id, item.product_name, item.category_id, item.category_name,
                  item.qty, item.cost );
            }
            items = sb.ToString( 0, sb.Length - 3 );
         }

         return string.Format( "apikey: [{0}], order_id: [{1}],  email_id: [{2}], email: [{3}], total: [{4}], order_date: [{5}] shipping: [{6}], tax: [{7}], store_id: [{8}], store_name: [{9}], plugin_id: [{10}], campaign_id: [{11}], line items: [{12}]",
            p.apikey, p.order.order_id, p.order.email_id, p.order.email, p.order.total, p.order.order_date,
            p.order.shipping, p.order.tax, p.order.store_id, p.order.store_name,
            p.order.plugin_id, p.order.campaign_id, items );


      }
      public static string FormatParms( generateTextParms p )
      {
         string genString = "";
         if ( p.content.GetType().Name == "String" )
            genString = p.content.ToString();
         else
            genString = ApiHelper.DictionaryToString( (Dictionary<string, string>)p.content );

         return string.Format( "apikey: [{0}], type: [{1}], content: [{2}]",
             p.apikey, p.type, genString );
      }
      public static string FormatParms( getAccountDetailsParms p )
      {
         return string.Format( "apikey: [{0}]", p.apikey );
      }
      public static string FormatParms( inlineCssParms p )
      {
         return string.Format( "apikey: [{0}], strip_css: [{1}], html: [{2}]",
             p.apikey, p.strip_css, p.html );
      }
      public static string FormatParms( listsForEmailParms p )
      {
         return string.Format( "apikey: [{0}], email_address: [{1}]", p.apikey, p.email_address );
      }
      public static string FormatParms( pingParms p )
      {
         return string.Format( "apikey: [{0}]", p.apikey );
      }

      #endregion

      #region ------------------------------------------------------------------- lists
      public static string FormatParms( listAbuseReportsParms p )
      {
         string since = ( p.since == DateTime.MinValue ) ? "" : ApiHelper.FormatApiDateParm( p.since );
         return string.Format( "apikey: [{0}], id: [{1}], start: [{2}], limit: [{3}], since: [{4}]",
            p.apikey, p.id, p.start, p.limit, since );
      }
      public static string FormatParms( listBatchSubscribeParms p )
      {
         string batch = "";
         if ( p.batch.Count > 0 )
         {
            StringBuilder sb = new StringBuilder();
            foreach ( Dictionary<string, object> entry in p.batch )
            {
               sb.AppendFormat( "{0} | ", ApiHelper.DictionaryToString( entry ) );
            }
            batch = sb.ToString( 0, sb.Length - 3 );
         }

         return string.Format( "apikey: [{0}], id: [{1}], double_optin: [{2}], update_existing: [{3}], replace_interests: [{4}], batch: [{5}]",
            p.apikey, p.id, p.double_optin, p.update_existing, p.replace_interests, batch );
      }
      public static string FormatParms( listBatchUnsubscribeParms p )
      {
         string emailString = ApiHelper.MakeStringFromList( p.emails );
         //
         return string.Format( "apikey: [{0}], id: [{1}], delete_member: [{2}], send_goodbye: [{3}], send_notify: [{4}], emails: [{5}]",
            p.apikey, p.id, p.delete_member, p.send_goodbye, p.send_notify, emailString );
      }
      public static string FormatParms( listGrowthHistoryParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}]", p.apikey, p.id );
      }
      public static string FormatParms( listInterestGroupAddParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}], group_name: [{2}]",
            p.apikey, p.id, p.group_name );
      }
      public static string FormatParms( listInterestGroupDelParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}], group_name: [{2}]",
            p.apikey, p.id, p.group_name );
      }
      public static string FormatParms( listInterestGroupUpdateParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}], old_name: [{2}], new_name: [{3}]",
            p.apikey, p.id, p.old_name, p.new_name );
      }
      public static string FormatParms( listInterestGroupsParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}]", p.apikey, p.id );
      }
      // -------------------------------------------------------------------------
      // listInterestGroupings
      public static string FormatParms( listInterestGroupingsParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}]", p.apikey, p.id );
      }
      // listInterestGroupingAdd
      public static string FormatParms( listInterestGroupingAddParms p )
      {
         string groups = ApiHelper.MakeStringFromList( p.groups );
         return string.Format( "apikey: [{0}], id: [{1}],  name: [{2}], type: [{3}],  groups: [{4}]",
            p.apikey, p.id, p.name, p.type, groups );
      }
      // listInterestGroupingDel
      public static string FormatParms( listInterestGroupingDelParms p )
      {
         return string.Format( "apikey: [{0}], grouping_id: [{1}]", p.apikey, p.grouping_id );
      }
      // listInterestGroupingUpdate
      public static string FormatParms( listInterestGroupingUpdateParms p )
      {
         return string.Format( "apikey: [{0}], grouping_id: [{1}], name: [{2}], value: [{3}]",
            p.apikey, p.grouping_id, p.name, p.value );
      }
      // -------------------------------------------------------------------------
      public static string FormatParms( listMemberInfoParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}], email_address: [{2}]",
            p.apikey, p.id, p.email_address );
      }
      public static string FormatParms( listMembersParms p )
      {
         string since = ( p.since == DateTime.MinValue ) ? "" : ApiHelper.FormatApiDateParm( p.since );

         return string.Format( "apikey: [{0}], id: [{1}], status: [{2}], since: [{3}], start: [{4}], limit: [{5}]",
            p.apikey, p.id, p.status, since, p.start, p.limit );
      }
      public static string FormatParms( listMergeVarAddParms p )
      {
         return string.Format(
            "apikey: [{0}], id: [{1}], tag: [{2}], name: [{3}], options.field_type: [{4}], options.req: [{5}], options.@public: [{6}], options.show: [{7}], options.default_value: [{8}], options.choices: [{9}]",
            p.apikey, p.id, p.tag, p.name, p.options.field_type, p.options.req, p.options.@public, p.options.show,
            p.options.default_value, ApiHelper.MakeStringFromList( p.options.choices ) );
      }
      public static string FormatParms( listMergeVarDelParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}], tag: [{2}]", p.apikey, p.id, p.tag );
      }
      public static string FormatParms( listMergeVarsParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}]", p.apikey, p.id );
      }
      public static string FormatParms( listMergeVarUpdateParms p )
      {
         string choices = "";
         if ( p.options.choices.Count > 0 ) choices = ApiHelper.MakeStringFromList( p.options.choices );

         return string.Format(
            "apikey: [{0}], id: [{1}], tag: [{2}], options.req: [{3}], options.@public: [{4}], options.show: [{5}], options.default_value: [{6}], options.choices: [{7}]",
            p.apikey, p.id, p.tag, p.options.req, p.options.@public, p.options.show,
            p.options.default_value, choices );
      }
      public static string FormatParms( listsParms p )
      {
         return string.Format( "apikey: [{0}]", p.apikey );
      }
      public static string FormatParms( listSubscribeParms p )
      {
         string mvString = "";
         if ( p.merge_vars.Count > 0 ) mvString = ApiHelper.DictionaryToString( p.merge_vars );

         return string.Format( "apikey: [{0}], id: [{1}], email_address: [{2}], merge_vars: [{3}], email_type: [{4}], double_optin: [{5}],  update_existing: [{6}],  replace_interests: [{7}], send_welcome: [{8}]",
            p.apikey, p.id, p.email_address, mvString, p.email_type,
            p.double_optin, p.update_existing, p.replace_interests, p.send_welcome );
      }
      public static string FormatParms( listUnsubscribeParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}], email_address: [{2}], delete_member: [{3}], send_goodbye: [{4}], send_notify: [{5}]",
             p.apikey, p.id, p.email_address, p.delete_member, p.send_goodbye, p.send_notify );
      }
      public static string FormatParms( listUpdateMemberParms p )
      {
         string mvString = ApiHelper.DictionaryToString( p.merge_vars );
         return string.Format( "apikey: [{0}], id: [{1}], email_address: [{2}], email_type: [{3}], replace_interests: [{4}], merge_vars: [{5}]",
             p.apikey, p.id, p.email_address, p.email_type, p.replace_interests, mvString );
      }
      public static string FormatParms( listWebhookAddParms p )
      {
         StringBuilder sb = new StringBuilder();
         //
         string actions = "";
         foreach ( var f in p.webhook_actions )
         {
            sb.AppendFormat( "{0}=>{1}, ", f.Key, f.Value );
         }
         actions = sb.ToString( 0, sb.Length - 2 );
         //
         sb = new StringBuilder();
         string sources = "";
         foreach ( var f in p.webhook_sources )
         {
            sb.AppendFormat( "{0}=>{1}, ", f.Key, f.Value );
         }
         sources = sb.ToString( 0, sb.Length - 2 );

         return string.Format( "apikey: [{0}], id: [{1}], url: [{2}], actions: [{3}], sources: [{4}]",
            p.apikey, p.id, p.url, actions, sources );
      }
      public static string FormatParms( listWebhookDelParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}], url: [{2}]", p.apikey, p.id, p.url );
      }
      public static string FormatParms( listWebhooksParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}]", p.apikey, p.id );
      }
      // -------------------------------------------------------------------------
      // listStaticSegments
      public static string FormatParms( listStaticSegmentsParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}]", p.apikey, p.id );
      }
      // listAddStaticSegment
      public static string FormatParms( listAddStaticSegmentParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}], name: [{2}]",
            p.apikey, p.id, p.name );
      }
      // listDelStaticSegment
      public static string FormatParms( listDelStaticSegmentParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}], seg_id: [{2}]", p.apikey, p.id, p.seg_id );
      }
      // listResetStaticSegment
      public static string FormatParms( listResetStaticSegmentParms p )
      {
         return string.Format( "apikey: [{0}], id: [{1}], seg_id: [{2}]", p.apikey, p.id, p.seg_id );
      }
      // listStaticSegmentAddMembers
      public static string FormatParms( listStaticSegmentAddMembersParms p )
      {
         string batch = ApiHelper.MakeStringFromList( p.batch );
         return string.Format( "apikey: [{0}], id: [{1}], seg_id: [{2}]", p.apikey, p.id, p.seg_id, batch );
      }
      // listStaticSegmentDelMembers
      public static string FormatParms( listStaticSegmentDelMembersParms p )
      {
         string batch = ApiHelper.MakeStringFromList( p.batch );
         return string.Format( "apikey: [{0}], id: [{1}], seg_id: [{2}]", p.apikey, p.id, p.seg_id, batch );
      }
      // -------------------------------------------------------------------------
      #endregion

      #region --------------------------------------------- Campaign Stats

      public static string FormatParms( campaignAbuseReportsParms p )
      {
         string since = ( p.since == DateTime.MinValue ) ? "" : ApiHelper.FormatApiDateParm( p.since );
         return string.Format( "apikey: [{0}], cid: [{1}], since: [{2}], start: [{3}], limit: [{4}]",
            p.apikey, p.cid, since, p.start, p.limit );
      }
      public static string FormatParms( campaignAdviceParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}]", p.apikey, p.cid );
      }
      public static string FormatParms( campaignAnalyticsParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}]", p.apikey, p.cid );
      }
      public static string FormatParms( campaignBounceMessagesParms p )
      {
         string since = ( p.since == DateTime.MinValue ) ? "" : ApiHelper.FormatApiDateParm( p.since );
         return string.Format( "apikey: [{0}], cid: [{1}], start: [{2}], limit: [{3}], since: [{4}]",
            p.apikey, p.cid, p.start, p.limit, since );
      }
      public static string FormatParms( campaignClickStatsParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}]", p.apikey, p.cid );
      }
      public static string FormatParms( campaignEcommOrdersParms p )
      {
         string since = ( p.since == DateTime.MinValue ) ? "" : ApiHelper.FormatApiDateParm( p.since );
         return string.Format( "apikey: [{0}], cid: [{1}], start: [{2}], limit: [{3}], since: [{4}]",
            p.apikey, p.cid, p.start, p.limit, since );
      }
      public static string FormatParms( campaignEepUrlStatsParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}]", p.apikey, p.cid );
      }
      public static string FormatParms( campaignEmailDomainPerformanceParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}]", p.apikey, p.cid );
      }
      public static string FormatParms( campaignGeoOpensParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}]", p.apikey, p.cid );
      }
      public static string FormatParms( campaignGeoOpensForCountryParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}], code: [{2}]", p.apikey, p.cid, p.code );
      }
      public static string FormatParms( campaignHardBouncesParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}], start: [{2}], limit: [{3}]",
            p.apikey, p.cid, p.start, p.limit );
      }
      public static string FormatParms( campaignSoftBouncesParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}], start: [{2}], limit: [{3}]",
            p.apikey, p.cid, p.start, p.limit );
      }
      public static string FormatParms( campaignStatsParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}]", p.apikey, p.cid );
      }
      public static string FormatParms( campaignUnsubscribesParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}], start: [{2}], limit: [{3}]",
            p.apikey, p.cid, p.start, p.limit );
      }

      #endregion

      #region --------------------------------------------- Campaign AIM Stats
      public static string FormatParms( campaignClickDetailAIMParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}], url: [{2}], start: [{3}], limit: [{4}]",
            p.apikey, p.cid, p.url, p.start, p.limit );
      }
      public static string FormatParms( campaignEmailStatsAIMParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}], email_address: [{2}]",
            p.apikey, p.cid, p.email_address );
      }
      public static string FormatParms( campaignEmailStatsAIMAllParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}], start: [{2}], limit: [{3}]",
                  p.apikey, p.cid, p.start, p.limit );
      }
      public static string FormatParms( campaignNotOpenedAIMParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}], start: [{2}], limit: [{3}]",
                  p.apikey, p.cid, p.start, p.limit );
      }
      public static string FormatParms( campaignOpenedAIMParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}], start: [{2}], limit: [{3}]",
                  p.apikey, p.cid, p.start, p.limit );
      }
      #endregion

      #region --------------------------------------------- Campaign Related
      public static string FormatParms( campaignContentParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}], for_archive: [{2}]",
            p.apikey, p.cid, p.for_archive );
      }
      public static string FormatParms( campaignCreateParms p )
      {
         // ------------------------------------------

         string tracking = string.Format( "opens=>{0}, html_clicks=>{1}, text_clicks=>{2}", p.options.tracking.opens, p.options.tracking.html_clicks, p.options.tracking.text_clicks );
         string analytics = "";
         if ( p.options.analytics.Count > 0 )
         { analytics = ApiHelper.DictionaryToString( p.options.analytics ); }

         string options = string.Format( "list_id: {0}, folder_id: {1}, subject: {2}, from_email: {3}, from_name: {4}, template_id: {5}, tracking: {6}, title: {7}, authenticate: {8}, analytics: {9}, inline_css: {10}, generate_text: {11}",
            p.options.list_id, p.options.folder_id, p.options.subject, p.options.from_email, p.options.from_name,
            p.options.template_id, tracking, p.options.title, p.options.authenticate, analytics, p.options.inline_css, p.options.generate_text );

         // ------------------------------------------
         string conditions = "";
         if ( p.segment_opts.conditions.Count > 0 )
         {
            StringBuilder sb = new StringBuilder();
            foreach ( campaignSegmentCondition c in p.segment_opts.conditions )
            {
               sb.AppendFormat( "{0}.{1}.{2}.{3}, ", c.field, c.op, c.value, c.extra );
            }
            conditions = sb.ToString( 0, sb.Length - 2 );
         }
         string segment_opts = string.Format( "match: {0}, conditions: {1}", p.segment_opts.match, conditions );
         // ------------------------------------------
         string content = ApiHelper.DictionaryToString( p.content );
         string type_opts = ApiHelper.DictionaryToString( p.type_opts );
         // ------------------------------------------
         return string.Format( "apikey: [{0}], type: [{1}], options: [{2}], segment_opts: [{3}], type_opts: [{4}], content: [{5}]",
            p.apikey, p.type, options, segment_opts, type_opts, content );
      }
      public static string FormatParms( campaignDeleteParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}]", p.apikey, p.cid );
      }
      public static string FormatParms( campaignEcommAddOrderParms p )
      {
         StringBuilder sb = new StringBuilder(); string items = "";
         if ( p.order.items.Count > 0 )
         {
            foreach ( var item in p.order.items )
            {
               sb.AppendFormat( "#{0}: ProdId=>{1}, ProdName=>{2}, CatId=>{3}, CatName=>{4}, Qty=>{5}, Cost=>{6:N2} | ",
                  item.line_num, item.product_id, item.product_name, item.category_id, item.category_name,
                  item.qty, item.cost );
            }
            items = sb.ToString( 0, sb.Length - 3 );
         }

         return string.Format( "apikey: [{0}], order_id: [{1}], campaign_id: [{2}], email_id: [{3}], total: [{4}], shipping: [{5}], tax: [{6}], store_id: [{7}], store_name: [{8}], plugin_id: [{9}], line items: [{10}]",
            p.apikey, p.order.order_id, p.order.campaign_id, p.order.email_id,
            p.order.total, p.order.shipping, p.order.tax, p.order.store_id, p.order.store_name,
            p.order.plugin_id, items );
      }
      public static string FormatParms( campaignFoldersParms p )
      {
         return string.Format( "apikey: [{0}]", p.apikey );
      }
      public static string FormatParms( campaignPauseParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}]", p.apikey, p.cid );
      }
      public static string FormatParms( campaignReplicateParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}]", p.apikey, p.cid );
      }
      public static string FormatParms( campaignResumeParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}]", p.apikey, p.cid );
      }
      public static string FormatParms( campaignsParms p )
      {
         string filters = "";
         if ( p.filters.Count > 0 )
         {
            StringBuilder sb = new StringBuilder(); string sVal = "";
            foreach ( var f in p.filters )
            {
               if ( f.Value.GetType().Name == "DateTime" )
                  sVal = ApiHelper.FormatApiDateParm( (DateTime)f.Value );
               else
                  sVal = f.Value.ToString();
               sb.AppendFormat( "{0}=>{1}, ", f.Key, sVal );
            }
            filters = sb.ToString( 0, sb.Length - 2 );
         }
         //
         return string.Format( "apikey: [{0}], filters: [{1}], start: [{2}], limit: [{3}]",
         p.apikey, filters, p.start, p.limit );

      }
      public static string FormatParms( campaignScheduleParms p )
      {
         string schedule_time = ( p.schedule_time == DateTime.MinValue ) ? "" : p.schedule_time.ToString( "yyyy-MM-dd HH:mm:ss" );
         string schedule_time_b = ( p.schedule_time_b == DateTime.MinValue ) ? "" : p.schedule_time_b.ToString( "yyyy-MM-dd HH:mm:ss" );
         //
         return string.Format( "apikey: [{0}], cid: [{1}], time: [{2}], time_b: [{3}]",
            p.apikey, p.cid, schedule_time, schedule_time_b );
      }
      public static string FormatParms( campaignSegmentTestParms p )
      {
         string conditions = "";
         if ( p.options.conditions.Count > 0 )
         {
            StringBuilder sb = new StringBuilder();
            foreach ( campaignSegmentCondition c in p.options.conditions )
            {
               if ( !string.IsNullOrEmpty( c.extra ) )
                  sb.AppendFormat( "{0}.{1}.{2}.{3}, ", c.field, c.op, c.value, c.extra );
               else
                  sb.AppendFormat( "{0}.{1}.{2}, ", c.field, c.op, c.value );
            }
            conditions = sb.ToString( 0, sb.Length - 2 );
         }
         return string.Format( "apikey: [{0}], list_id: [{1}], match: [{2}], conditions: [{3}]",
              p.apikey, p.list_id, p.options.match, conditions );
      }
      public static string FormatParms( campaignSendNowParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}]", p.apikey, p.cid );
      }
      public static string FormatParms( campaignSendTestParms p )
      {
         string emailString = ApiHelper.MakeStringFromList( p.test_emails );
         return string.Format( "apikey: [{0}], cid: [{1}], test_emails: [{2}], send_type: [{3}]",
            p.apikey, p.cid, emailString, p.send_type );
      }
      //
      public static string FormatParms( campaignShareReportParms p )
      {
         StringBuilder sb = new StringBuilder(); string opts = "";
         if ( p.opts.Count > 0 )
         {
            foreach ( var opt in p.opts )
            {
               if ( opt.Key.ToLower() != "theme" )
               {
                  sb.AppendFormat( "{0}=>{1}, ", opt.Key, opt.Value.ToString() );
               }
               else
               {
                  sb.Append( "theme: [" );
                  foreach ( var tc in opt.Value as Dictionary<string, string> )
                  {
                     sb.AppendFormat( "{0}=>{1}, ", tc.Key, tc.Value );
                  }
                  sb.Remove( sb.Length - 1, 1 );
                  sb.Append( "]" );
               }
            }
            opts = sb.ToString( 0, sb.Length - 2 );
         }

         return string.Format( "apikey: [{0}], cid: [{1}], opts: [{2}]",
            p.apikey, p.cid, opts );
      }

      //
      public static string FormatParms( campaignTemplatesParms p )
      {
         return string.Format( "apikey: [{0}]", p.apikey );
      }
      public static string FormatParms( campaignUnscheduleParms p )
      {
         return string.Format( "apikey: [{0}], cid: [{1}]", p.apikey, p.cid );
      }
      public static string FormatParms( campaignUpdateParms p )
      {
         string showValue = "";
         string type = p.value.GetType().Name;
         if ( type.Contains( "Dictionary" ) ) type = "Dictionary";
         switch ( type )
         {
            case "String":
            case "Int32":
            case "Boolean":
               showValue = p.value.ToString();
               break;
            case "campaignTracking":
               campaignTracking tracking = (campaignTracking)p.value;
               showValue = string.Format( "opens: {0}, html_clicks: {1}, text_clicks: {2}",
                  tracking.opens, tracking.html_clicks, tracking.text_clicks );
               break;
            case "campaignSegmentOptions":
               campaignSegmentOptions seg_opts = (campaignSegmentOptions)p.value;
               string conditions = "";
               if ( seg_opts.conditions.Count > 0 )
               {
                  StringBuilder sb = new StringBuilder();
                  foreach ( campaignSegmentCondition c in seg_opts.conditions )
                  {
                     sb.AppendFormat( "{0}.{1}.{2}.{3}, ", c.field, c.op, c.value, c.extra );
                  }
                  conditions = sb.ToString( 0, sb.Length - 2 );
               }
               showValue = string.Format( "match: {0}, conditions: {1}", seg_opts.match, conditions );

               break;
            case "Dictionary":
               showValue = ApiHelper.DictionaryToString( (Dictionary<string, string>)p.value );
               break;
            default:
               showValue = EnumValues.NotSupplied;
               break;
         }
         // --------------------------------- ---------- -------------------------------------------
         return string.Format( "apikey: [{0}], cid: [{1}], name: [{2}], value: [{3}]",
             p.apikey, p.cid, p.name, showValue );
      }
      #endregion


   }
}